#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1005;

int n, m;
int a[N];
int f[N], st[N][10];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
void init() {
  rep(i, 2, n) f[i] = f[i >> 1] + 1;
  rep(i, 1, n) st[i][0] = a[i];
  rep(j, 1, f[n]) {
    int len = 1 << j;
    rep(i, 1, n + 1 - len) st[i][j] = gcd(st[i][j - 1], st[i + len / 2][j - 1]);
  }
}
int query(int l, int r) {
  int len = (r + 1 - l);
  int k = f[len];
  len = 1 << k;
  return gcd(st[l][k], st[r + 1 - len][k]);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  init();
  while (m--) {
    int l, r;
    cin >> l >> r;
    if (l > r) swap(l, r);
    cout << query(l, r) << endl;
  }
  return 0;
}